package com.cold.demo.webflux.filter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.server.RequestPath;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilterChain;
import reactor.core.publisher.Mono;

import java.net.URI;

@Component
public class CommonWebFilter implements org.springframework.web.server.WebFilter {

    private Logger log = LoggerFactory.getLogger(CommonWebFilter.class);

    /**
     * 过滤器 类似于servlet中的Filter类
     */
    @Override
    public Mono<Void> filter(ServerWebExchange serverWebExchange, WebFilterChain chain) {
        ServerHttpRequest request = serverWebExchange.getRequest();
        URI uri = request.getURI();// http://localhost:8080/index
        RequestPath path = request.getPath();// /index
        log.info("请求：" + uri.getPath());
        return chain.filter(serverWebExchange);
    }
}
